package com.master.demo.example.java8;

import java.util.StringJoiner;

/**
 * StringJoiner使用demo
 * Java8拼接字符串
 * 运用StringBuilder一个拼接字符串的封装处理
 *
 * @author: Yang
 * @date: 2021/6/24
 * @version: 1.0.0
 * Copyright Ⓒ 2021 Master Computer Corporation Limited All rights reserved.
 */
public class StringJoinerExample {

    public static void main(String[] args) {
        addLineDelimiter();
    }

    /**
     * 普通拼接字符串
     * ab
     */
    private static void add() {
        StringJoiner sj = new StringJoiner("");
        sj.add("a").add("b");
        System.out.println(sj);
    }

    /**
     * 带分割符拼接字符串
     * a，b
     */
    private static void addDelimiter() {
        StringJoiner sj = new StringJoiner("，");
        sj.add("a").add("b");
        System.out.println(sj);
    }

    /**
     * 换行拼接字符串
     * a，b
     */
    private static void addLineDelimiter() {
        StringJoiner sj = new StringJoiner(System.lineSeparator());
        sj.add("a").add("b");
        System.out.println(sj);
    }

    /**
     * 带前后缀拼接字符串
     * [a，b]
     */
    private static void addDelimiterFix() {
        StringJoiner sj = new StringJoiner("，", "[", "]");
        sj.add("a").add("b");
        System.out.println(sj);
    }

}
